﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Enterprises.Wpf.Core.Net
{
    /// <summary>
    /// 异形消息对象，用于异形客户端的注册包接收以及验证使用
    /// </summary>
    public class AlienMessage : NetMessageBase, INetMessage
    {
        /// <inheritdoc cref="P:HslCommunication.Core.IMessage.INetMessage.ProtocolHeadBytesLength" />
        public int ProtocolHeadBytesLength => 5;

        /// <inheritdoc cref="M:HslCommunication.Core.IMessage.INetMessage.CheckHeadBytesLegal(System.Byte[])" />
        public override bool CheckHeadBytesLegal(byte[] token)
        {
            if (base.HeadBytes == null)
            {
                return false;
            }
            if (base.HeadBytes[0] == 72 && base.HeadBytes[1] == 115 && base.HeadBytes[2] == 110)
            {
                return true;
            }
            return false;
        }

        /// <inheritdoc cref="M:HslCommunication.Core.IMessage.INetMessage.GetContentLengthByHeadBytes" />
        public int GetContentLengthByHeadBytes()
        {
            return base.HeadBytes[3] * 256 + base.HeadBytes[4];
        }
    }
}
